package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateLecturerDialog;
import pl.prv.polanie.client.dto.CSLecturerDTO;
import pl.prv.polanie.client.dto.CSVLecturerDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableLecturers;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class LecturersList extends ObjectsList {

	TableLecturers tableLecturers = new TableLecturers(this);

	public LecturersList() {
		
		CSLecturerDTO[] ls = Cache.getAllLecturers();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableLecturers);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSLecturerDTO cs = ls[i];
			CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(cs);
			
			tableLecturers.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateLecturerDialog cld = new CreateLecturerDialog(LecturersList.this, null); 
				cld.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableLecturers.removeSelectedLecturerFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSLecturer(CSLecturerDTO csLecturer) {
//		CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(csLecturer);
		
		tableLecturers.saveOrUpdateLecturerInTable(csLecturer);
//		tableLecturers.addRow(csLecturer, csv);
	}
	
	public void removeSelectdCSLecturer() {
		tableLecturers.removeSelectedLecturerFromTable();
	}
	
}
